package testUnit.deptUnitTest;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;

import com.situ.staff.department.dao.DepartmentDao;
import com.situ.staff.department.model.DepartmentModel;

public class deptTest {
	DepartmentDao dao = new DepartmentDao();

	@Test
	public void testInsert() {
		DepartmentModel model = new DepartmentModel("a01", "开发二部", "333");
		try {
			dao.insert(model);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("插入成功");
	}

	@Test
	public void testDeleteByCode() {
		DepartmentModel model = new DepartmentModel("a01", "开发一部", "111");
		try {
			dao.deleteByCode(model);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		System.out.println("删除一条记录");
	}

	@Test
	public void testDelete() {
		DepartmentModel model = new DepartmentModel("a01", "", "");
		try {
			dao.delete(model);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		System.out.println("删除一条记录");
	}

	@Test
	public void testUpdateAll() {
		DepartmentModel model = new DepartmentModel("a02", "开发6部", "666");
		try {
			dao.updateAll(model);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("更新完成");
	}

	@Test
	public void testUpdateActive() {
		DepartmentModel model = new DepartmentModel("a02", null, "888");
		try {
			dao.updateActive(model);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("更新部分字段完成");
	}

	@Test
	public void testselectList() {
		DepartmentModel model = new DepartmentModel(null, "开发二部", null);
		List<DepartmentModel> list = new ArrayList<DepartmentModel>();
		try {
			list = dao.selectList(model);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(list.size());
	}
	
	@Test
	public void testselectModel() {
		DepartmentModel model = new DepartmentModel("a02", null, "");
//		List<DepartmentModel> list = new ArrayList<DepartmentModel>();
		DepartmentModel m1 = new DepartmentModel();
		try {
			m1 = dao.selectModel(model);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(m1.toString());
	}
}
